from django.db import models


class Shop(models.Model):
    user = models.ForeignKey("users.User", related_name='shop', null=True, on_delete=models.CASCADE,
                             verbose_name="用户id")
    title = models.CharField(max_length=50, null=False, verbose_name='团购标题')
    price = models.CharField(max_length=10, verbose_name='团购价格')
    info = models.CharField(max_length=200, default='', verbose_name='团购描述')
    place = models.CharField(max_length=100, verbose_name="取货详细地址")
    # click_nums = models.IntegerField(default=0, verbose_name="活动查看次数")
    count_least = models.IntegerField(default=0, verbose_name="团购最少报名人数")
    receive_time = models.CharField(max_length=40, verbose_name='收货时间')
    end_time = models.CharField(max_length=40, verbose_name='团购结束时间')
    image_urls = models.CharField(max_length=200, null=True, verbose_name='活动图片')
    image_description = models.CharField(max_length=200, null=True, verbose_name='团购图片描述')
    count_max = models.IntegerField(default=0, verbose_name="团购最多报名人数")
    destiny_title = models.CharField(max_length=30, default="", null=True, verbose_name='活动图片标题')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = "tb_shop"
        verbose_name = "团购"
        verbose_name_plural = verbose_name

    def __str__(self):
        return "%s: %s" % (self.id, self.title)


class ShopComments(models.Model):
    '''评论表'''
    shop = models.ForeignKey(Shop, related_name='shop_comments', verbose_name='评论的团购')
    user = models.ForeignKey('users.User', related_name="comments", verbose_name="用户")
    parent = models.ForeignKey('self', related_name='sub_comments', default=None, null=True, verbose_name='回复评论')
    content = models.TextField(null=False, verbose_name='评论内容')
    like_count = models.IntegerField(default=0, verbose_name='评论点赞')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = "tb_shop_comments"
        verbose_name = "评论表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content


